package Leetcode.每日一题;

import java.util.Scanner;

public class 小美的01串翻转 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String binaryString = scanner.nextLine(); // 读取输入的01串
        scanner.close();

        int totalWeight = calculateWeight(binaryString);
        System.out.println(totalWeight);
    }

    private static int calculateWeight(String binaryString) {
        int totalWeight = 0;
        int length = binaryString.length();

        // 对于每个字符，计算以该字符结尾的子串的权值
        for (int i = 0; i < length; i++) {
            int weight = 0;
            int count0 = 0, count1 = 0;

            // 计算以当前字符结尾的子串的权值
            for (int j = i; j < length; j++) {
                if (binaryString.charAt(j) == '0') {
                    count1++; // 遇到1之前的0的个数
                } else {
                    count0++; // 遇到0之前的1的个数
                }
                weight += Math.min(count0, count1); // 权值是min(count0, count1)
            }

            totalWeight += weight;
        }

        return totalWeight;
    }
}
